﻿using UnityEngine;
using System.Collections;

public class RepeatMovement : MonoBehaviour
{
    public float MoveSpeed;
    public Vector3 Position1, Position2;
    Vector3 direction;
    float distance;
    private void Awake()
    {
        direction = (Position2 - Position1).normalized;
        distance = Vector3.Distance(Position1, Position2);
    }
    void Update()
    {
        transform.position = Position1 + Mathf.PingPong(Time.time * MoveSpeed, distance) * direction;
    }
}
